% Define the range of gray levels
r = linspace(0, 1, 256); % Assuming 256 gray levels

% Calculate the transformed gray levels using the given transformation
s = r.^2 - (2/3) * r.^3;

% Plot the original and transformed histograms
figure;
subplot(2, 1, 1);
plot(r, 6 * r .* (1 - r), 'LineWidth', 2);
title('Original Histogram');
xlabel('Gray Level (r)');
ylabel('Probability (pr)');
grid on;

subplot(2, 1, 2);
plot(s, ones(size(s)), 'LineWidth', 2);
title('Transformed Histogram');
xlabel('Gray Level (s)');
ylabel('Probability (ps)');
grid on;